package com.github.wui.utils;


import android.content.Context;
import android.graphics.drawable.GradientDrawable;

/**
 * @author Mr.xie
 * @Date 2025/4/29
 */
public class ViewUtils {


    /**
     * 设置 圆角
     *
     * @param gradientDrawable 渐变drawable 对象 可以用于设置圆角
     * @param leftTopRound     左上圆角
     * @param rightTopRound    右上圆角
     * @param rightBottomRound 右下圆角
     * @param leftBottomRound  坐下圆角
     */
    public static void setRound(GradientDrawable gradientDrawable, float leftTopRound, float rightTopRound, float rightBottomRound, float leftBottomRound) {
        gradientDrawable.setCornerRadii(new float[]{leftTopRound, leftTopRound, rightTopRound, rightTopRound, rightBottomRound, rightBottomRound, leftBottomRound, leftBottomRound});
    }


    /**
     * dp 转 px
     *
     * @param context 上下文对象
     * @param dpValue dp值
     */
    public static int dp2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }


    /**
     * px 转 dp
     *
     * @param context 上下文镀锡
     * @param pxValue px值
     */
    public static int px2dp(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }


    public static float measureTextSize(String text, float testSize) {
        return text.length() * testSize;
    }


    public static void sleep(long mills){
        try {
            Thread.sleep(mills);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
